<?php

namespace app\apiweb\controller;

//use app\api\loader\Services;
use app\apishop\validate\UserValidate;
use app\common\controller\Api;
use think\Config;
use think\Exception;

/**
 * 会员接口
 */
class User extends Api
{
    protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
    protected $noNeedRight = '*';
    protected $failException = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->modelUser = new \app\admin\model\shop\User();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }

    }


    /**
     * 注册会员
     *
     * @ApiMethod (POST)
     */
    public function register()
    {
        $input = input('post.');
        try {
            $this->validate($input, UserValidate::class . '.shop_register');
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }
        $ret = $this->auth->register($input['mobile'], $input['pwd'], $input['mobile'] . '@qq.com', $input['mobile'], []);
        if ($ret) {
            unset($input['pwd']);
            $input['user_id']=$ret;
            $this->modelUser->insert($input);
            $this->success(__('Sign up successful'));
        } else {
            $this->error($this->auth->getError());
        }
    }


}
